package com.nameli.admin.service.impl;

import com.nameli.SIM.bean.entity.AreaInfo;
import com.nameli.SIM.mapper.AreaInfoMapper;
import com.nameli.SIM.util.tree.MyTreeUtils;
import com.nameli.SIM.util.tree.TreeNode;
import com.nameli.admin.service.AreaService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author NAME-L
 * @Description 籍贯信息service实现类
 * @className AreaServiceImpl
 * @date 2021-12-06 15:49:01
 */
@Service
public class AreaServiceImpl implements AreaService {

    private static final Log log = LogFactory.getLog(AreaServiceImpl.class);

    @Autowired
    private AreaInfoMapper areaInfoMapper;

    @Override
    public List<TreeNode<AreaInfo>> queryAll() {
        List<AreaInfo> list = areaInfoMapper.queryAll();
        List<TreeNode<AreaInfo>> treeNodes = MyTreeUtils.listToTree(list , (node) ->{
            TreeNode<AreaInfo> treeNode = new TreeNode<>();
            treeNode.setId(node.getAreaId());
            treeNode.setParentId(node.getParentId());
            treeNode.setRaw(node.getAreaName());
            return treeNode;
        } , -1);
        return treeNodes;
    }
}
